/*******************************************************************************
 * Copyright (c) 2008 Smart Mai(smardio@gmail.com).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Smart Mai(smardio@gmail.com) - initial API and implementation
 ******************************************************************************/
package com.smartdio.company.views;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;

import com.smartdio.company.Activator;
import com.smartdio.company.Messages;
import com.smartdio.company.Resources;

/**
 * @author smart
 * 
 */
public class CompanyEditDialog extends TitleAreaDialog {
	public CompanyEditPanel editPanel;

	private boolean edit = false;

	/**
	 * @param parentShell
	 * @param edit
	 */
	public CompanyEditDialog(Shell parentShell, boolean edit) {
		super(parentShell);
		this.edit = edit;
	}

	/**
	 * @param parentShell
	 */
	public CompanyEditDialog(Shell parentShell) {
		super(parentShell);

	}

	@Override
	protected Control createDialogArea(Composite parent) {
		if (edit) {
			setTitleImage(Activator.getDefault().getImage(
					Resources.WIZARD_COMPANY_EDIT));
			setTitle(Messages.getString("CompanyEditDialog.edit_company_msg")); //$NON-NLS-1$
			getShell().setText(
					Messages.getString("CompanyEditDialog.edit_company_msg")); //$NON-NLS-1$

		} else {
			setTitleImage(Activator.getDefault().getImage(
					Resources.WIZARD_COMPANY_NEW));
			setTitle(Messages.getString("CompanyEditDialog.create_new_company")); //$NON-NLS-1$
			getShell().setText(
					Messages.getString("CompanyEditDialog.create_new_company")); //$NON-NLS-1$
		}
		GridData gridData1 = new GridData();
		gridData1.grabExcessHorizontalSpace = true;
		gridData1.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
		gridData1.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
		gridData1.heightHint = -1;
		gridData1.grabExcessVerticalSpace = true;
		editPanel = new CompanyEditPanel(parent, SWT.None);
		editPanel.setLayoutData(gridData1);
		parent.pack();
		
		// 添加动态帮助
		IWorkbenchHelpSystem help = PlatformUI.getWorkbench().getHelpSystem();
		help.setHelp(parent, "com.smartdio.company.companydialog");
		return editPanel;
	}

	@Override
	protected Point getInitialSize() {
		return new Point(320, 280);
	}

}
